/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package be.contribute.common.utils;

import be.contribute.common.pojo.TextMessage;

/**
 *
 * @author debian
 */
public class StringUtil {
    
    public static Double getDoubleFromString(String pInput, String pDelimiter)
    {
        if(pInput.indexOf(pDelimiter) > -1)
        {  
            String buffer = pInput.substring(pInput.indexOf(pDelimiter)+1);
            return Double.parseDouble(buffer.substring(0,buffer.indexOf(pDelimiter)));
        }
        return null;
    }
    
    public static Integer getIntFromString(String pInput, String pDelimiter)
    {
        if(pInput.indexOf(pDelimiter) > -1)
        {  
            String buffer = pInput.substring(pInput.indexOf(pDelimiter)+1);
            return Integer.parseInt(buffer.substring(0,buffer.indexOf(pDelimiter)));
        }
        return null;
    }
    
    public static TextMessage getTextMessageFromString(String pInput)
    {
        String[] data = pInput.split(",");
        Integer id = Integer.parseInt(data[0].substring(data[0].lastIndexOf(":")+2));
        String nbr = data[2].substring(1,data[2].length()-1);
        String time = data[4].substring(1,data[4].length()) + " " + data[5].substring(0,data[5].length()-4);
        return new TextMessage(id,nbr,time);
    }
    
}

